package gaishocron.notifier.istudy;

import gaishocron.notifier.istudy.meta.ISBlogNotifierUserMeta;
import gaishocron.notifier.istudy.model.ISBlogNotifierUser;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slim3.datastore.Datastore;

import com.google.appengine.api.datastore.Email;

public class IStudyBlogNotifierDataCreator extends HttpServlet {

    private static final long serialVersionUID = 1L;
    final static ISBlogNotifierUserMeta userMeta = ISBlogNotifierUserMeta.get();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        List<ISBlogNotifierUser> userList = new ArrayList<ISBlogNotifierUser>();
        userList.add(createISNotiferUserModel("abcde", "abcde@gmail.com"));
        
        Datastore.put(userList);
        
        resp.getWriter().println("OK");

    }

    private ISBlogNotifierUser createISNotiferUserModel(String id, String email) {
        ISBlogNotifierUser user = new ISBlogNotifierUser();
        user.setId(Datastore.createKey(userMeta, id));
        user.setEmail(new Email(email));
        return user;
    }

}
